package com.rabbitmq.topicdemo.controller;

import com.rabbitmq.topicdemo.config.TopicConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class SendMessage {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @RequestMapping("/send")
    public String sendMessage(){
        Map<String,String> map1=new HashMap<>();
        map1.put("phone","12345678910");
        map1.put("nickname","topicUser");
        map1.put("appV","1");
        Map<String,String> map2=new HashMap<>();
        map2.put("phone","12345678910");
        map2.put("nickname","topicUser");
        map2.put("appV","2");
        rabbitTemplate.convertAndSend(TopicConfig.TOPIC_EXCHANGE,"app1.order.pay",map1);
        rabbitTemplate.convertAndSend(TopicConfig.TOPIC_EXCHANGE,"app2.order.pay",map2);
        rabbitTemplate.convertAndSend(TopicConfig.TOPIC_EXCHANGE,"app1.order.insert",map1);
        rabbitTemplate.convertAndSend(TopicConfig.TOPIC_EXCHANGE,"app1.order.msg",map1);
        rabbitTemplate.convertAndSend(TopicConfig.TOPIC_EXCHANGE,"app2.order.msg",map2);
        //消息体是个object ， 可以是自定义对象 ，但是接受的时候也要按类型接收
        return "success";
    }
}
